#ifndef PLOTTER_H
#define PLOTTER_H

#include "AtlasStyle.C"
#include "AtlasUtils.C"
#include "NAssymetricError.C"
#include "Utility.C"
#include "PlotQCD.C"
#include "TCanvas.h"
#include "TString.h"
#include "TH1D.h"

/**
 Common options:

  - hist_fpath   : specifies filepath containing input histograms
  - ijet         : specifies the jet bin for plot
  - ierr         : specifies the uncertainty mode, 0: stat+sys, 1: stat, 2: sys 
  - qcd          : specifies if drawing data-driven QCD estimations 
  - mc_qcd       : specifies if drawing QCD Monte-Carlo samples
  - mc_qcd_scale : specifies the scaling factor for the QCD Monte-Carlo samples
  - log[x|y]     : specifies if drawing log scale on axis [x|y] 
  - log[x|y]     : specifies if drawing log scale on axis [x|y] 
*/

// plot Mjjj variance mass
TCanvas* plot_mtop(TString hist_fpath,
                   const int ijet=0, const int ierr=0);

// plot loose->tight efficiency based on data sample 
TCanvas* plot_eff_l2t_data(TString hist_fpath, const int ijet=0);

// plot loose->tight efficiency based on MC sample 
TCanvas* plot_eff_l2t_mc(TString hist_fpath, const int ijet=0,
                         const bool inc_mcqcd=false, const bool inc_data=false);

// plot B-tagged jets multiplicity 
TCanvas* plot_nbjets(TString hist_fpath, const int ijet=0, const bool logy=false,
                     const bool qcd=true, const int ierr=0);

// plot B-tagged jets multiplicity 
TCanvas* plot_njets(TString hist_fpath, const int ijet=0, const bool logy=false,
                    const bool qcd=true, const int ierr=0);

// plot W transverse mass 
TCanvas* plot_mwt(TString hist_fpath, const int ijet=0,
                  const bool qcd=true, const bool mc_qcd=false, const double mc_qcd_scale=1.0, const int ierr=0);

// calculate and plot the systematic uncertaining coming from the control region 
TCanvas * cal_ctrl_syserr(vector<TString> hist_fpaths, Double_t d0sig_norm=5.0, const int ijet=4);

// calculate and plot the systematic uncertaining coming from the performance of the method 
TCanvas * cal_perf_syserr(TString hist_fpath, const int ijet=0, const int ierr=0, const bool logy=false);

// calculate the scale factor from QCD MC to QCD data-driven estimation
void cal_mc2data_sfactor(TString hist_fpath);

// calculate the systematic uncertainty coming from the prompt-muon (ttbar, W/Z+jets) contamination 
void cal_contamination_syserr(TString hist_fpath);

// fix the bin labelling for jet multiplicity plots 
void set_jet_binlabel(TH1D *hist, const bool max_inc=false) {

    TAxis *x = hist->GetXaxis();
 
    for( int i=1; i <= hist->GetNbinsX(); i++) {
        ostringstream stm;
        stm << i-1;

        if ( i==hist->GetNbinsX() && max_inc ) {
            x->SetBinLabel(i, "#geq" + TString(stm.str()) );
        } else {
            x->SetBinLabel(i, TString(stm.str()) );
        }
    }
}

// parse the d0sig (contral region) from the given input histogram file 
Double_t parse_d0sig(TString hist_fpath) {

    Double_t d0sig;

    TObjArray *fpath   = hist_fpath.Tokenize("/");
    TString hist_fname = ((TObjString *) fpath->At( fpath->GetEntries()-1 ))->GetString();

    TObjArray *finfo   = hist_fname.Tokenize("_");
    TString d0sig_str  = (((TObjString *) finfo->At(3))->GetString()).ReplaceAll(".root",5,"",0);

    return d0sig_str.Atof();
}

#endif
